home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / moreexamples / example2 / example2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  3.8 KB  |  107 lines

  1.                            /*  Example2.c
  2.                                This code follows the overview of gadgets doc
  3.                                included with this developer disk.
  4.  
  5.                                Patrick Hager, Great Valley Products Inc.
  6.                                October 30, 1993
  7.                            */
  8.  
  9. #include <stdio.h>
  10. #include "/global/userwindow.h"
  11. #include "/global/egslibraries.h"
  12.  
  13. #include <egs/egsintui.h>
  14. #include <egs/clib/egsintui_protos.h>
  15. #include <egs/pragmas/egsintui_pragmas.h>
  16. #include <egs/egsgadbox.h>
  17. #include <egs/clib/egsgadbox_protos.h>
  18. #include <egs/pragmas/egsgadbox_pragmas.h>
  19.  
  20.  
  21. #define TESTING_ID 200
  22.  
  23.  
  24. struct UserInputWindow Example_Request;
  25.  
  26. EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow);
  27. void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
  28.  
  29. void main (void) {
  30.  
  31.   if (OpenEGSLibraries ()) {
  32.     Init_UserWindow (&Example_Request, "Example Window",WINDOW_MODAL,NULL,
  33.                      NULL);
  34.     Example_Request.Create = Create_Example;
  35.     Example_Request.GadgetDown = GadgetDown_Example;
  36.     Example_Request.IDCMPFlags = EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
  37.                                  EI_iNEWSIZE | EI_iGADGETDOWN;
  38.     Example_Request.Flags =      EI_SIZEBBOTTOM| EI_SIMPLE_REFRESH |
  39.                                  EI_GIMMEZEROZERO;
  40.     Example_Request.SysGadgets = (EI_WINDOWCLOSE)|(EI_WINDOWSIZE)|EI_WINDOWDRAG;
  41.  
  42.     if (Open_UserWindow (&Example_Request,-1,-1)) {
  43.       Close_UserWindow (&Example_Request);
  44.     }
  45.     else
  46.       printf ("Couldn't open my window!\n");
  47.   }
  48.   CloseEGSLibraries ();  // after the bracket cause what if I opened 3 but
  49.                          // couldn't find the rest, still need to close the 3.
  50. }
  51.  
  52. /*************************************
  53.    PRIVATE:  Create_Example.
  54.              This routine is called by the UserWindow routines.
  55.              It passes back a GadBoxPtr to the gadgets wanted.
  56. *************************************/
  57. EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow) {
  58.   EB_GadBoxPtr root,verti;
  59.   EB_GadContext gadcon;
  60.  
  61.   gadcon = UserWindow->GadCon;
  62.  
  63.   root = EB_CreateHorizBox (gadcon);
  64.   EB_AddLastSon (root,EB_CreateHorizFill (gadcon,0,0));
  65.     verti = EB_CreateVertiBox (gadcon);
  66.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  67.     EB_AddLastSon (verti,EB_CreateTextAction (gadcon,"Gadget 1",TESTING_ID,EB_FILL_ALL));
  68.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  69.     EB_AddLastSon (verti,EB_CreateTextAction (gadcon,"Gadget 2",TESTING_ID+1,EB_FILL_ALL));
  70.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  71.   EB_AddLastSon (root, verti);
  72.   EB_AddLastSon (root,EB_CreateHorizFill (gadcon,0,0));
  73.     verti = EB_CreateVertiBox (gadcon);
  74.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  75.     EB_AddLastSon (verti,EB_CreateTextAction (gadcon,"Gadget 3",TESTING_ID+2,EB_FILL_ALL));
  76.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  77.     EB_AddLastSon (verti,EB_CreateTextAction (gadcon,"Gadget 4",TESTING_ID+3,EB_FILL_ALL));
  78.     EB_AddLastSon (verti,EB_CreateVertiFill (gadcon,0,0));
  79.   EB_AddLastSon (root,verti);
  80.   EB_AddLastSon (root,EB_CreateHorizFill (gadcon,0,0));
  81.  
  82.   return root;
  83. }
  84.  
  85. /**************************************
  86.     PRIVATE:  GadgetDown_Example.
  87.               This routine handles the gadget down events passed to the
  88.               Example Control Window.
  89. **************************************/
  90. void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
  91.  
  92.  
  93.   switch (iaddress->GadgetID) {
  94.     case TESTING_ID:
  95.       printf ("You hit Gadget 1!\n");
  96.     break;
  97.     case TESTING_ID+1:
  98.       printf ("You hit Gadget 2!\n");
  99.     break;
  100.     case TESTING_ID+2:
  101.       printf ("You hit Gadget 3!\n");
  102.     break;
  103.     case TESTING_ID+3:
  104.       printf ("You hit Gadget 4!\n");
  105.     break;
  106.   }
  107. }